package karaoke.servlets;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.Cliente;
import karaoke.modelo.Sala;
import karaoke.modelo.Persona;
import karaoke.negocio.GestionSala;
import karaoke.negocio.GestionComentario;

/**
 * Servlet implementation class ComentarSalaServlet
 */
@WebServlet("/ComentarSalaServlet")
public class ComentarSalaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ComentarSalaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try{
			
			GestionComentario ges = new GestionComentario();
			
			//int idCliente = 3;
			int idCliente = Integer.parseInt(request.getParameter("codPersona"));
			int idSala  = Integer.parseInt(request.getParameter("gesala"));
			
						
			//String idSala = request.getParameter("gesala");
			System.out.println(idSala);
			String calificacion = request.getParameter("calif");
			String comentario = request.getParameter("txtComentario");
			//String campo = "";
		
				
				/*HttpSession sesion = request.getSession();
				Cliente cli = (Cliente)sesion.getAttribute("USUARIO_ACTUAL");*/
				
				//comentario =  idCliente + ": " + comentario + " " + calificacion.toString()  + " puntos." + "comentado por " + cli;
				ges.insertar(idSala, idCliente, calificacion, comentario);			
				request.setAttribute("MENSAJE", "Se registro correctamente su comentario.");
			
			    	
			} catch (DAOExcepcion e) {
				e.printStackTrace();
				request.setAttribute("MENSAJE", e.getMessage());
			}
			
			 catch (IllegalArgumentException e2) {
			
				e2.printStackTrace();
				request.setAttribute("MENSAJE", "ERROR, Falta llenar campos o tipo de variable no soportada: -" + e2.getMessage() + "-");
			 }
			
			
				RequestDispatcher rd = request.getRequestDispatcher("ComentarioSala.jsp");
				rd.forward(request, response);
			
		}
		
	}


